<?php require_once('Connections/learnConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}



  $colname_nilai = $_POST['nis'];
  $colname_nilai1 = $_POST['smt'];
  $colname_nilai2 = $_POST['ta'];

mysql_select_db($database_learnConn, $learnConn);
$query_nilai = sprintf("SELECT * FROM nilai WHERE nis=%s AND tahun_ajaran=%s AND semester=%s", 
					   GetSQLValueString($colname_nilai, "text"),
					   GetSQLValueString($colname_nilai2, "text"),
					   GetSQLValueString($colname_nilai1, "text"));

$nilai = mysql_query($query_nilai, $learnConn) or die(mysql_error());
$row_nilai = mysql_fetch_assoc($nilai);
$totalRows_nilai = mysql_num_rows($nilai);
$rata = 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hasil Nilai</title>
<link href="style/style.css" type="text/css" rel="stylesheet" />
<link href="style/pro_drop_1.css" type="text/css" rel="stylesheet"/>
<script src="style/stuHover.js" type="text/javascript"></script>
</head>

<body><center>

<table width="900" bgcolor="#FFFFFF">
	<?php
	include "topmenu.php";
	?>
    <tr>
    	<td id="menu">
        <ul>
        	<li><a href="index.php">Home</a></li>
            <li><a href="profil.php">Profil</a></li>
        	<li><a href="fasilitas.php">Fasilitas</a></li>
            <li><a href="kegiatan.php">Kegiatan</a></li>
        	<li><a href="pengumuman.php">Pengumuman</a></li>
            <li><a href="buku_tamu.php">Buku Tamu</a></li>
        	<li><a href="nilai_jadwal.php">Nilai & Jadwal</a></li>
            <li><a href="login.php">Login</a></li>
        </ul>
        </td>
    	<td id="konten"><?php
		if ($totalRows_nilai !=0) {
			echo "Hasil Untuk Nilai <i>".$_POST['nis']."</i> Ditemukan Untuk Tahun Ajaran ".$_POST['ta']." Semester ".$_POST['smt'];
		}
		else {
			echo "Hasil Untuk Nilai <i>".$_POST['nis']."</i> Tidak Ditemukan Untuk Tahun Ajaran ".$_POST['ta'];
		}
		?>
    	  <br />
        <table width="100%">
  <tr bgcolor="#CCCCCC">
    <td rowspan="2">Mata Pelajaran</td>
    <td colspan="5" align="center" bgcolor="#00FF00">Ulangan</td>
    <td colspan="5" align="center" bgcolor="#0066FF">Tugas</td>
    <td rowspan="2">UTS</td>
    <td rowspan="2">UAS</td>
   <td rowspan="2">Nilai<br />Akhir</td>
  </tr>
  <tr>
    <td bgcolor="#00FF00">1</td>
    <td bgcolor="#00FF00">2</td>
    <td bgcolor="#00FF00">3</td>
    <td bgcolor="#00FF00">4</td>
    <td bgcolor="#00FF00">5</td>
    <td bgcolor="#0066FF">1</td>
    <td bgcolor="#0066FF">2</td>
    <td bgcolor="#0066FF">3</td>
    <td bgcolor="#0066FF">4</td>
    <td bgcolor="#0066FF">5</td>
    </tr>
  <?php do { ?>
    <tr bgcolor="#FFFF00">
      <td><?php 
  		$colname_matpell = $row_nilai['kd_matpel'];
		mysql_select_db($database_learnConn, $learnConn);
		$query_matpell = sprintf("SELECT * FROM matpel WHERE kd_matpel = %s", GetSQLValueString($colname_matpell, "text"));
		$matpell = mysql_query($query_matpell, $learnConn) or die(mysql_error());
		$row_matpell = mysql_fetch_assoc($matpell);
		$totalRows_matpell = mysql_num_rows($matpell);
		echo $row_matpell['nama_matpel']; ?></td>
      <td bgcolor="#00FF00"><?php echo $row_nilai['ul1']; ?></td>
      <td bgcolor="#00FF00"><?php echo $row_nilai['ul2']; ?></td>
      <td bgcolor="#00FF00"><?php echo $row_nilai['ul3']; ?></td>
      <td bgcolor="#00FF00"><?php echo $row_nilai['ul4']; ?></td>
      <td bgcolor="#00FF00"><?php echo $row_nilai['ul5']; ?></td>
      <td bgcolor="#0066FF"><?php echo $row_nilai['tgs1']; ?></td>
      <td bgcolor="#0066FF"><?php echo $row_nilai['tgs2']; ?></td>
      <td bgcolor="#0066FF"><?php echo $row_nilai['tgs3']; ?></td>
      <td bgcolor="#0066FF"><?php echo $row_nilai['tgs4']; ?></td>
      <td bgcolor="#0066FF"><?php echo $row_nilai['tgs5']; ?></td>
      <td><?php echo $row_nilai['uts']; ?></td>
      <td><?php echo $row_nilai['uas']; ?></td>
      <td><?php echo $row_nilai['nilai_akhir'];
	  $rata=$rata + $row_nilai['nilai_akhir'];
 ?></td>
    </tr>
    <?php } while ($row_nilai = mysql_fetch_assoc($nilai)); ?>
    <tr>
      <td colspan="7" align="left">
	  <!-- <a href="javascript:window.print()">Print</a> -->
	  <?php
		$colname_nilai = $_POST['nis'];
		//echo $colname_nilai . "<hr>";
		$colname_nilai1 = $_POST['smt'];
		$colname_nilai2 = $_POST['ta'];
		
		echo "<a href='nilai_hasil_pdf.php?nis=$colname_nilai&smt=$colname_nilai1&ta=$colname_nilai2' target='_blank'>Print</a>";
  ?>
	  </td>
      <td colspan="7" align="right">Rata-rata = <?php 
	  $ratarata=0;
	  if($totalRows_nilai != 0) {
	  $ratarata = $rata / $totalRows_nilai; 
	  echo number_format($ratarata , 2); 
	  } else {
		  echo $ratarata;
	  }
	   ?></td>
    </tr>
        </table>

        
        </td>
    </tr>
    <tr>
    	<td colspan="2" id="footer">Copyright 2012</td>
    </tr>
    
</table></center>
</body>
</html>
<?php
mysql_free_result($matpell);

mysql_free_result($nilai);
?>
